package com.backstage.common.error;

import com.backstage.common.base.bean.Message;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * @Project authority
 * @Package com.backstage.common.error
 * @Data 2017/7/13下午 1:10.
 * @Aurhor 阮雪峰
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody //在返回自定义相应类的情况下必须有，这是@ControllerAdvice注解的规定
    public Message exceptionHandler(RuntimeException e) {
        e.printStackTrace();
        Message m = Message.SYSTEM_ERROR.setMessage(e.getCause().getMessage());
        return m;
    }
}
